package com.example.neptune.zyfypt_109zj.fragment;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.example.neptune.zyfypt_109zj.R;

import static android.content.Context.MODE_PRIVATE;

public class Fragment6 extends Fragment {
    private  TextView tvinfo,tvusername;
    private Button btfh;
    private View view=null;
    private Context context;
    private SharedPreferences sp;
    private String username;
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        context=getActivity();
       //动态加载Fragment1的布局文件
        view=inflater.inflate(R.layout.fragment6,container,false);
        //获取布局上的控件，注意通过view获取
        tvinfo=(TextView)view.findViewById(R.id.textView8);
        tvusername=(TextView)view.findViewById(R.id.tvusername);
        btfh=(Button)view.findViewById(R.id.button6) ;
        tvinfo.setText("欢迎使用资源复用平台系统！");
        sp=context.getSharedPreferences("login",MODE_PRIVATE);
        readSP();
        tvusername.setText(username);
        btfh.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                switch (v.getId()){
                    case R.id.button6:
                        getActivity().onBackPressed();
                        break;
                }
            }
        });
        //注意Toast第一个参数上下文
        Toast.makeText(context, "加载Fragment微信", Toast.LENGTH_SHORT).show();
        //返回动态生成的view
        return view;
    }

    private void readSP() {
        username = sp.getString("username", null);
    }
}
